package com.woke.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;

import com.woke.adapter.Mybanklistbadter;
import com.woke.data.Datas_bankedcard;
import com.zhongcai.online.R;

import java.util.ArrayList;

/**
 * 作者 ： 暗网
 * 创建时间：2017/3/13
 * 备注：  银行卡 账号列表
 */

public class BankAccountFragment extends DialogFragment implements AdapterView.OnItemClickListener {


	private ArrayList<Datas_bankedcard> mAccountList;
	private OnItemClickListener mItemClickListener;

	public void setOnItemClickListener(OnItemClickListener listener) {
		mItemClickListener = listener;
	}

	@Override
	public void onCreate(@Nullable Bundle savedInstanceState) {
		super.onCreate (savedInstanceState);
		setStyle (DialogFragment.STYLE_NORMAL, R.style.DialogFragment_Full);
		mAccountList = (ArrayList<Datas_bankedcard>) getArguments ().getSerializable ("banklist");
	}


	@Nullable
	@Override
	public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		View rootView = inflater.inflate (R.layout.item_adater_banklist, container, false);
		ImageView mView1 = (ImageView) rootView.findViewById (R.id.item_banklist_back);
		ListView mListView = (ListView) rootView.findViewById (R.id.item_banklist_listview);
		mListView.setOnItemClickListener (this);
		Mybanklistbadter adapter = new Mybanklistbadter (inflater, mAccountList);
		mListView.setAdapter (adapter);

		mView1.setOnClickListener (new View.OnClickListener () {

			@Override
			public void onClick(View v) {
				dismiss ();
			}
		});
		return rootView;
	}

	@Override
	public void onStart() {
		super.onStart ();
		DisplayMetrics dm = getResources ().getDisplayMetrics ();
		getDialog ().getWindow ().setLayout (dm.widthPixels, dm.heightPixels);

	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

		if (mItemClickListener != null) {
			mItemClickListener.onItemClick (mAccountList.get (position), position);
		}
		dismiss ();
	}

	public interface OnItemClickListener {
		public void onItemClick(Datas_bankedcard cardNo, int postion);
	}
}
